package com.mornd.gulimall.member.web.v1;

import com.mornd.gulimall.apis.order.IOrderClient;
import com.mornd.gulimall.apis.order.to.OrderPageTo;
import com.mornd.gulimall.common.core.exception.ServiceException;
import com.mornd.gulimall.common.core.result.R;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @author: mornd
 * @dateTime: 2023/8/28 - 9:23
 */

@Controller
public class OrderRouteController {

    @Resource
    private IOrderClient orderClient;

    /**
     * 支付成功后跳转的订单列表页面
     *
     * @return
     */
    @GetMapping("/orderList.html")
    public String orderList(@RequestParam(value = "pageNo", required = false, defaultValue = "1") long pageNo,
                            @RequestParam(value = "pageSize", required = false, defaultValue = "10") long pageSize,
                            Model model) {
        OrderPageTo orderPageTo = new OrderPageTo();
        orderPageTo.setPageNo(pageNo);
        orderPageTo.setPageSize(pageSize);
        R<OrderPageTo> r = orderClient.pageOrderWithItemByUser(orderPageTo);
        if (r.isOk()) {
            model.addAttribute("orderTo", r.getData());
            return "orderList";
        }
        throw new ServiceException("订单查询失败，" + r.getMsg());
    }
}
